package com.petmall.mapper;

import java.util.List;
import com.petmall.entity.Cart;
import org.apache.ibatis.annotations.*;

/**
 * Created by pig2guang on 2017/4/3.
 */
@Mapper
public interface CartMapper {

    @Select("select * from tb_cart where user_id = #{user_id}")
    public List<Cart> selectCartByUserId(long user_id);

    @Insert("insert into tb_cart(user_id,item_id,num) values(#{user_id}, #{item_id}, #{num})")
    public void insertItem(@Param("user_id") long user_id, @Param("item_id") long item_id, @Param("num") long num);

    @Update("update tb_cart set num = num + #{num}  where user_id = #{user_id} and item_id = #{item_id}")
    public void updateItemNumberInCart(@Param("user_id") long user_id, @Param("item_id") long item_id, @Param("num") int num);

    @Delete("delete from tb_cart where user_id = #{user_id} and item_id = #{item_id}")
    public void deleteItemByItemId(@Param("user_id") long user_id, @Param("item_id") long item_id);

    @Delete("delete from tb_cart where user_id = #{user_id}")
    public void deleteAllItemsByUserId(@Param("user_id") long user_id);

}
